package com.ahy231.mapper;

import com.ahy231.dto.GetUsers;
import com.ahy231.entity.Friend;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ahy231
 * @date 2021/7/28 14:32
 * @description
 */
@Mapper
public interface FriendMapper extends BaseMapper<Friend> {

    /**
     * 获取所有联系人
     * @param userId 本人用户 id
     */
    @Select("SELECT user_id, username, img_url FROM friend f LEFT JOIN `user` u ON f.utwo_id = u.user_id WHERE f.uone_id = #{userId}")
    List<GetUsers> getFriends(long userId);

    /**
     * 模糊搜索联系人
     * @param userId 本人用户 id
     * @param username 模糊搜索联系人用户名
     */
    @Select("SELECT u.user_id, u.username " +
            "FROM friend f LEFT JOIN `user` u ON f.utwo_id = u.user_id " +
            "WHERE f.uone_id = #{userId} " +
            "AND u.username LIKE CONCAT('%',#{username},'%')")
    List<GetUsers> queryFriend(long userId, String username);
}
